package cn.life.common.utils;


public class SoftKey {

    com.softkey.jsyunew3 j9;
    SoftKey()
    {
        j9=new  com.softkey.jsyunew3();
    }

    private String myhex(byte indata)
    {
        String outString;
        outString=String.format("%X",indata);
        if(outString.length()<2)outString="0"+outString;
        return outString;
    }

    //若某字节为负数则需将其转成无符号正数
    private  long conver(byte temp){
        long tempInt = (int)temp;
        if(tempInt < 0){
            tempInt += 256;
        }
        return tempInt;
    }

    //以下用于将16进制字符串转化为无符号长整型
    private int HexToInt(String s)
    {
        String [] hexch = { "0", "1", "2", "3", "4", "5", "6", "7",
                "8", "9", "A", "B", "C", "D", "E", "F"};
        int i, j;
        int r, n, k;
        String ch;

        k = 1; r = 0;
        for (i = s.length(); i > 0; i--)
        {
            ch = s.substring(i - 1,  i-1+1);
            n = 0;
            for (j = 0; j < 16; j++)
            {
                if (ch.compareToIgnoreCase(hexch[j]) ==0 )
                {
                    n = j;
                }
            }
            r += (n * k);
            k *= 16;
        }
        return r;
    }


    public String  StrEnc(String InString , String Key)//使用增强算法，加密字符串
    {

        byte [] b,outb;
        byte []temp_b=InString.getBytes();
        byte [] temp=new byte[8],outtemp=new byte[8];
        int n,i,nlen,outlen;
        String outString;

        nlen = temp_b.length;
        nlen=nlen+1;
        if( nlen < 8 )
            outlen = 8;
        else
            outlen = nlen;
        b=new byte[outlen];
        outb=new byte[outlen];

        for(n=0;n<nlen-1;n++)
        {
            b[n]=temp_b[n];
        }

        outb=b.clone();

        for( n = 0; n<=outlen - 8 ;n=n+ 8)
        {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            EnCode(temp, outtemp, Key);
            for( i = 0 ;i<8;i++) outb[i + n] = outtemp[i];
        }

        outString = "";
        for (n = 0 ;n<= outlen - 1;n++)
        {
            outString = outString +myhex(outb[n]) ;
        }
        return outString;
    }

    public String  StrDec(String InString , String Key)//使用增强算法，解密字符串
    {

        byte [] b,outb;
        byte [] temp=new byte[8],outtemp=new byte[8];
        int n,i,nlen,outlen;
        String outString,temp_String;


        nlen = InString.length();
        if( nlen < 16 ) outlen = 16;
        outlen = nlen / 2;
        b=new byte[outlen];
        outb=new byte[outlen];

        i = 0;
        for (n = 1 ;n<= nlen ;n=n+2)
        {
            temp_String = InString.substring(n-1, n-1+2);
            b[i] = (byte)HexToInt(temp_String);
            i = i + 1;
        }

        outb=b.clone();

        for( n = 0; n<=outlen - 8 ;n=n+ 8)
        {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            DeCode(temp, outtemp, Key);
            for( i = 0 ;i<8;i++) outb[i + n] = outtemp[i];
        }

        outString=new String(outb);
        outString=outString.trim();
        return outString;
    }

    public void EnCode(byte[] inb, byte[] outb,  String Key )
    {

        long cnDelta,y,z,a,b,c,d,temp_2;
        long [] buf=new long[16];
        int n,i,nlen;
        long sum;
        long temp,temp_1;
        long mask=4294967295L;

        //UInt32 temp, temp_1;
        String temp_String ;


        cnDelta = 2654435769L;
        sum = 0;

        nlen = Key.length();
        i = 0;
        for( n = 1 ;n<= nlen ;n=n+2)
        {
            temp_String =Key.substring(n-1, n-1+2);
            buf[i] =HexToInt(temp_String);
            i = i + 1;
        }
        a = 0 ; b = 0 ; c = 0 ; d = 0;
        for(n = 0;n<=3;n++)
        {
            a = (buf[n] << (n * 8)) | a;
            b = (buf[n + 4] << (n * 8)) | b;
            c = (buf[n + 4 + 4] << (n * 8)) | c;
            d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
        }


        y = 0;
        z = 0;
        for(n = 0;n<=3;n++)
        {
            temp_2 = conver(inb[n]);
            y = (temp_2 << (n * 8)) | y;
            temp_2 = conver(inb[n + 4]);
            z = (temp_2 << (n * 8)) | z;
        }


        n = 32;

        while (n > 0)
        {
            sum = (cnDelta + sum)& mask;

            temp = (z << 4) & mask;
            temp = (temp + a) & mask;
            temp_1 = (z + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (z >> 5) & mask;
            temp_1 = (temp_1 + b) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (temp + y) & mask;
            y = temp & mask;
           /*y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); */

            temp = (y << 4) & mask;
            temp = (temp + c) & mask;
            temp_1 = (y + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (y >> 5) & mask;
            temp_1 = (temp_1 + d) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (z + temp) & mask;
            z = temp & mask;
           /* z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); */
            n = n - 1;

        }
        for(n = 0;n<=3;n++)
        {
            outb[n] = (byte)((y >>> (n * 8)) & 255);
            outb[n + 4] =(byte)((z >>> (n * 8)) & 255);
        }
    }

    public void DeCode(byte[] inb, byte[] outb,  String Key )
    {

        long cnDelta,y,z,a,b,c,d,temp_2;
        long [] buf=new long[16];
        int n,i,nlen;
        long sum;
        long temp,temp_1;

        long mask=4294967295L;

        //UInt32 temp, temp_1;
        String temp_String ;


        cnDelta = 2654435769L;
        sum = 3337565984L;

        nlen = Key.length();
        i = 0;
        for( n = 1 ;n<= nlen ;n=n+2)
        {
            temp_String =Key.substring(n-1, n-1+2);
            buf[i] =HexToInt(temp_String);
            i = i + 1;
        }
        a = 0 ; b = 0 ; c = 0 ; d = 0;
        for(n = 0;n<=3;n++)
        {
            a = (buf[n] << (n * 8)) | a;
            b = (buf[n + 4] << (n * 8)) | b;
            c = (buf[n + 4 + 4] << (n * 8)) | c;
            d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
        }


        y = 0;
        z = 0;
        for(n = 0;n<=3;n++)
        {
            temp_2 = conver(inb[n]);
            y = (temp_2 << (n * 8)) | y;
            temp_2 = conver(inb[n + 4]);
            z = (temp_2 << (n * 8)) | z;
        }


        n = 32;

        while (n > 0)
        {


            temp = (y << 4) & mask;
            temp = (temp + c) & mask;
            temp_1 = (y + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (y >> 5) & mask;
            temp_1 = (temp_1 + d) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (z - temp) & mask;
            z = temp & mask;
           /* z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); */

            temp = (z << 4) & mask;
            temp = (temp + a) & mask;
            temp_1 = (z + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (z >> 5) & mask;
            temp_1 = (temp_1 + b) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (y - temp ) & mask;
            y = temp & mask;
           /*y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); */

            sum = (sum-cnDelta)& mask;
            n = n - 1;

        }
        for(n = 0;n<=3;n++)
        {
            outb[n] = (byte)((y >>> (n * 8)) & 255);
            outb[n + 4] =(byte)((z >>> (n * 8)) & 255);
        }
    }

    public  long get_LastError()
    {
        return j9.get_LastError();
    }

    public String FindPort(int start)
    {
        return j9.FindPort(start);
    }



    //使用带长度的方法从指定的地址读取字符串
    private String ReadStringEx(int addr, String DevicePath)
    {
        int nlen, ret;
        byte[] buf = new byte[1];
        //先从地址0读到以前写入的字符串的长度
        ret = j9.YReadEx((short)addr, (short)1, "1A901576", "FF10F28B", DevicePath);
        if (ret != 0) return "";
        nlen = j9.GetBuf(0);
        //再读取相应长度的字符串
        return j9.NewReadString(addr + 1, nlen, "1A901576", "FF10F28B", DevicePath);

    }
    //使用从储存器读取相应数据的方式检查是否存在指定的加密锁
    public int CheckKeyByReadEprom()
    {
        int n, ret;
        String DevicePath = "";//用于储存加密锁所在的路径
        String outString = "";
        //@NoUseCode_data return 1;//如果没有使用这个功能，直接返回1
        for (n = 0; n < 255; n++)
        {
            DevicePath= j9.FindPort(n );
            if (j9.get_LastError() != 0) return (int)j9.get_LastError();
            outString = ReadStringEx(0, DevicePath);
            if ((j9.get_LastError() == 0) && (outString.compareTo("李佳明，明远科技公司，xxxx@163.com") == 0)) return 0;
        }
        return -92;
    }
    //使用增强算法一检查加密锁，
    public int CheckKeyByEncstring()
    {
        int n, ret;
        String DevicePath = "";//用于储存加密锁所在的路径
        String outString = "";
        int myrnd = (int)(Math.random() * 500);
        String[] EncInString ={ "28540","29850","27023","13769","10201","17774","10590","32643","20274","25036","15626","10791","15952","26456","21422","4196","11551","22100","29826","1167","27816","25506","2274","12952","16661","27331","1607","8721","23472","32729",
                "14411","22573","29923","8616","10920","6591","1593","2960","13112","19766","9306","10132","7157","31909","30993","8277","27897","30656","23881","4886","22143","5592","4876","25016","15072","6110","8065","9406","22677","10853",
                "17653","15690","5179","1950","7378","1821","25224","14684","20896","10906","21082","31504","30986","3779","13992","15310","3547","27448","28813","16453","2556","31294","22852","25801","8311","19126","19493","32588","6006","12833",
                "20652","24928","16963","24225","25714","31286","6984","2298","25905","6306","32271","18060","6852","19731","323","31577","24867","27549","28844","27652","29289","11762","26422","28623","20689","30051","2282","17052","20659","11491",
                "23794","30444","17035","19204","18328","2018","15602","29687","9286","2879","1699","15247","32646","871","8310","1854","28931","20824","28517","4117","5510","18105","1677","1223","10488","22472","4390","19365","16485","28010",
                "23689","25761","9206","22303","562","27471","18677","23818","12730","14560","27596","29164","6875","9765","18950","1321","30575","28048","31819","29887","13680","11572","28774","8021","16633","2243","835","5674","28226","27534",
                "15080","28448","935","27272","8323","14010","25505","17987","14939","538","22218","3313","9691","8449","30171","23650","20877","28626","13233","17419","22299","18831","1860","18172","30032","6617","13741","32231","10773","3827",
                "15399","22816","27763","27582","23053","663","1687","31165","15064","24542","4040","6930","16418","13353","1649","31870","27556","25159","2589","26468","26938","20141","13684","13254","14558","24939","6210","23109","30888","10292",
                "20847","9764","20180","6234","18695","1861","29626","28877","2611","1065","23510","15394","15677","19442","450","29321","16783","26723","20533","15317","26547","4063","11277","20856","19284","5989","7745","131","19771","1178",
                "7661","19369","11602","16317","31304","11579","17570","26034","25776","31020","24407","14843","6814","24333","14011","14522","12201","3090","2870","18608","30606","27914","24147","3393","4135","4203","19644","22636","2924","10307",
                "2109","15573","14712","11333","29115","16318","4742","7109","21318","11017","16622","24498","14852","32566","19244","19617","28735","1387","24025","17602","5988","358","13743","31208","25082","907","10632","20357","28076","23259",
                "21598","23722","15685","9977","24396","3594","21166","2599","27530","26614","26865","31558","7284","26721","20024","14298","16771","2269","24013","22018","8273","24731","6683","30338","24216","26222","26281","5821","3122","21191",
                "25125","691","19737","8634","24662","26373","9064","13558","1065","761","22871","5584","31140","31340","2882","22328","20468","18405","20898","6081","29538","20098","2833","9116","18265","3080","17993","13980","24673","27350",
                "19492","24114","24101","13297","18844","31601","25968","8442","6604","25867","14891","3634","12268","10577","31071","19578","8536","28726","29496","4952","20360","32075","9472","4843","12825","20932","21279","9717","16577","28273",
                "17184","9177","32093","13765","5550","21144","7655","28112","16529","30933","22135","25159","10421","4051","17225","9851","23587","5489","29365","30556","27653","32306","3896","15743","26277","18234","10600","12053","29037","10314",
                "8706","4591","744","26050","13280","7551","15550","17063","7674","31960","26042","4762","28011","28844","968","27611","26477","4429","5615","31054","4956","12460","28249","27765","25774","23643","11346","3955","1280","32653",
                "22083","30470","15883","9492","5047","21653","938","22881","1879","26654","7637","11400","18668","4678","29351","21560","32609","1613","28762","28102" };
        String[] EncOutString ={ "191DC9ACAA876366","2C64A43E6C97903A","0F9830AC2150B3DF","EF95AE50D7549555","5B82403EAE71BABC","76B0B909D3A4DA10","AB838289ACEC4465","A7D6B7F8E7262C52","C80B84350BC26FE1","96DCB6CFD01366B0","858B2401D981A692","66ADAE8133E8EE2B","4F82CD8A6448DDBB","C642C4735933EFE7","8D8B1D8BBE3066E6","7D3374AE1EBF92E2","6A5D228DABD386AE","F9121082B3881B43","B51BF8DFDC520FA9","FF79A1027AF0F931","26F23010AB92EF20","167979FC426A684F","D29CD06D63AB299C","A83ACDA8D8D423B8","1AB5ED01735791A1","06F978EF68E64473","6DD6FA29E75E4AB8","5809DED671E92A32","E17E9F1D66209C4E","8394E8261C24D98F",
                "CA728202D22750DA","6C7FC3FA25A3EA98","7545497150768826","072B33A838CCDE12","E10046BB7943D5FF","E2A85FEC0CE83988","F92C9D99B417E63D","91832E3150EB0A3A","E6CBD40E424E37D4","8AE3DE5AD0D2AB27","BB729DA1A24C1CB5","A30C029F6C384EDF","49C4014CDB69AACF","DC7E5263C2B1818D","64BE55615425C2AE","1F51932A959A6029","4864E3512F11CB8C","BE9DB94245A2760D","C449D10669DB2BAE","B34CF853D850F47E","E418210DBF4F1768","8344150E5D2C5D0C","E70538080698FCED","1A627F067CD12816","27A11B3219791E19","15F5A5F4BBE2C6FA","8904819631FA5E8D","CDA5BFE085897DDF","5A8DE0859E2B137A","84AE451FF85F7774",
                "97CD0FE7EA9CF715","56D89890CBFABC00","6AB5587628A778B4","F5409825A52419C1","D74B58A83AAB1309","247847969A2EAB8E","8BED6C58BCE34F8B","5C47F867E489DB9C","4620FA90E25A8D14","B67A9CD258BE734F","27C47E51023F3EEE","AB99839CC9C4E6AE","523F4A2C0EB326AE","0BC818A8E1E27388","C027B64E79F9EBA1","5F547742693C6953","E623BD007CE2BE54","745FBFBDF16389ED","A8C9551435EDC591","357AF6F20F9D16EE","9C98F4B257FDA31E","971384EDFB18DCEA","706CD825C80016FC","DA6F8C4F12C65512","298E4DF5382A83EB","38D71ADC2360C136","809EA10459D67316","9CE42ECC10854FE6","934A85C0E2033172","20D6C0D679180300",
                "15D5B358A5E18DBD","AD3D859BD4FA5509","4F753B9225E1CFF4","C640AEB247FBF455","E4866DE94179C319","0FF5A8D3AC43F94A","388D55C7C2CFC6CF","BA386A793B1C8C6E","1DE7C43C9EF09BD6","731DCA9B3A9C033B","972986836162D865","5618B4C60D6090F2","65F8488C603A2D50","6072995173DE752C","8F8D815EBBBD83D7","5605492D58B8B9A9","8C3ADFC3E0081660","425D825C035C5A10","FB65655BE6997B29","9E6054E6BACB002B","8359B9E645C2B023","2EA3F40D01BA720D","F26CE252AB875339","0DECD6157F0E250D","9DC4BE32C7541B64","3E5C7B2732320BE4","10CF049320C2FA04","B3DF487701DE480D","7E8077893F68607C","141636156C61D032",
                "28E56982631E961C","12B4F5792071A9CA","165D07C1A771F19E","799251FB8EC1A563","53AC30F8C45127F5","6D010CA7C2A4F3E3","BD802AE100771152","67B9AFFA505D3C71","D9954E524E527D96","40A10E35D28C3E56","57A208C034CA7F2D","DD37327EAAB237A3","86F3C463ED125506","D10667295A3A9858","0E995DD32379BB3E","B9AA4F52B6CE3375","0D74B53FB2358D39","1D2EB3B8596B2CAE","4B3BA8164AF03A06","1279BCFDACD6FF1D","83770642653CFC6A","68EE3A8005D0AD48","4E62F7D1AED9A4DB","8C01C1DA81BF34FE","1AC1254A85348660","102A9D281462396C","59708AED88C1B912","2C332878F46C8017","D7A59D670B69427F","EEA4E95993EC009E",
                "303388A7799146C7","CF4651FAA389166C","01C6C19F044CEBFC","D530C20B3AAA1233","608A84149A248A29","94273CE5ACFFB33B","4D161CFB73B59F03","A019AB4CF2B24724","746EFEF9883F0A96","6317BACB9006FF16","4850200AE10F6E15","D6BA5634F99FF9C9","EE8B5CC0600B4A02","E8463B6F8851FDB5","7C41DB8B0C2307A1","DAC26A444A7F4B26","EA4915F258D3A371","7DC83D56E865F444","B431EC5C8FBD815C","1366837E1B0358D2","320953B73FA82B75","3B2BD28C0D4BBF3C","4CDB236486B8C164","0A35B2BCB1F45BEE","6FF3350FFAAAA9B7","C14068B1D2135CB6","21D4E9F73845A098","E7EB8A90FA212F83","A55F10DC0FFA6CD2","F3DE0ACA7C13822F",
                "1C0AD3410412E467","1390AABABF190104","2938B5F01B9BBD6F","6E21F768D04A21DB","989421499AAA4D10","9811D9E3281FBFA5","F7A1C245E6346176","8D6087BABE81A877","9BCEB448D49D7F8A","1BBD3CE801AC4A4B","AABF7F56AA916861","58510EB7CC06EA17","731AAD00C5748177","69C275B03D766D3D","EFFC6CF5ED85E442","C2D05599C6CFAF19","D12B377D862230F7","0AC8B37D8CF5ABA6","B0299E34113ECA86","3A79099598B8DC6C","5ED8F2C62A7DB52E","9D2042828EC6E11C","1C9CD5D34519BC5F","F262753849A754E9","D8B96842ED05C5D0","C9EEE283B5D31D44","940098E57D71E959","A4F5CAAA74A7AB5B","F77B5199FC64B8BA","D5D34865A36599AF",
                "17632AFEC518E7E7","44658FE610D6F740","7FD468421F9DB0BB","A65FE61CF396F624","846B18933E57F4FB","128C7DBF5F8C90E2","77221F45D2D8A1FB","D36CCE60992F783C","C74FD089A6C3BF1E","1A7687095B64EECE","12BC4825A292388D","EA13360008F13369","BF64D29D84D72156","B25F157BE079820E","E531F4B13173BB24","71DE51648B333DE9","0217B789E788FD6D","9B91C5057CD27A70","734A1E5017E86654","AEBC7D1C721EE681","B1F51E0EC85A2F40","30838CE9E3E86404","7B5B7C682412246D","B7F90D17627091BA","E16239006292EE4E","600256AAA7CF6731","8B7E6C9AE57A5FD2","567B1950ED9A952E","EE34D572252FAEA7","B9AEB0C4295AC48A",
                "862FCA3DD1622F1E","026EE093E93898AD","53F7F3166D4084B1","8436155E384FE73E","DAB0AC2B6E15497A","3D5F459E1093AC00","2AC1C65E28A20BBF","07E91DFD80F0C896","1939C04AD4CCC6AA","8A27A2B13FEA0921","42D356994D968174","6437B78DAB39CBC8","2F53B4BBF83AC14F","FC33878D3C7B9997","A9C64BAD771EA188","1EEE308714A31388","8D7E4B4C1A0BDFA8","5D80D9E411FCD1C1","9525ABC9A3BD6A5B","4A4864AFDEF3E733","5ABA1C81E1F0F2F7","E1B3CBC1A496D22E","8886F1E9D1216BCF","7D9B54479C411796","7454D2232D071E6C","E4F26ABE1FA8727A","CB61BCECD796BB08","F8AC50B5894C9AA3","A5884E32086F975D","9D13B6381775160B",
                "CCF6D4640C8B1945","B8B4ABFB2335D1C1","BF95BC5ECFA44D2C","888855676503A557","921646DA35E38233","74BA7C4A1D7A8553","003CCECB747BDB43","20428D6B637DE09B","1BAC2009A965F7D7","F1F52774AB58D2F8","235352AF855F07B8","1C9F2CDAC543CFCB","50FB64BF373FCF6C","526B8B99133C1406","76217B0D860300D7","350DB2E41D677352","62B019DD2A366DA3","7F5C8C6DFD337F01","277F1F9D6F860C5C","264230FD18079B8D","32B23F0797B5B9F6","1095B79A7EAC7CC4","087BC46AE4E17B04","E77ADCCFB8847FA2","26E492C9F5E1D4A2","4B2DD16387877F3C","74550EC84B82E610","9ACE337A870307C8","4FE4688C7E1089E0","36CACF72DFAB7463",
                "FBDCF98A890A15EA","96D981EACFB403EB","50303158F2DE230F","DB8FD072270010D7","939FC4CF22C0ABA3","246C91D65F793B32","131A7014A7E331F6","3271E45996B4709B","60C9124C2217756F","F4719F887EE06CF1","18E52D341F3D14DE","F22664001DC11095","D7609500FB11227C","06D4182E2C657421","5981EC02311ED475","0CF62EA9255961D7","8714EF87397DE68B","EBFD8F14B6EA7CA3","5E8E334641B25DB2","4143632021797E34","14ECEF63D8A2B072","682D41B4FCF63FA2","D2847392D2C4D0FA","BD56A73619FA9C0D","23337DEE42F2B870","6F3873235B529B78","F9DB2086F7C0ABB4","43117203B31DFDD5","1DCA85AC0CFFA704","FBF8C18EE8F1177F",
                "89A71C66233DF08F","5AD2A0967F236442","4741CF9739F2A219","BD53A14CAEF71952","4C62999603593EAA","488536AE9E67BE97","A2AB6766AA8C6892","7FA501C76D7056AD","A47A1858F726217B","C851ADF94774988C","B6160125A0B48580","20A45627D01A8252","AD78A8C2208E3335","F0DD79D04FD0EB68","814D0368E6A3DADF","B84219AF819F4F07","D53B4C4C7ABE38BB","2DC9639BAB7DE526","02CE027007C482B0","E1DF9B9F1DE6577F","EE0EAC2F2A1B63C0","0ACB08CC3C01EA90","AAF6C9234F170107","288675E4FE754ACA","B4044F45DC1F6F57","7A9A6AC187D457D1","03972B5DC9DC533D","F085169AAFFF07B6","17BDAC0C7895E8D9","D9212F92A0502A6C",
                "0C8836126FC62FDA","4287E8585AEE9C1A","51C8E2C3C70EFD4F","BD21711596FBDCC2","9355737F8C097FED","6ABE7DB2CD1A40A0","89AE97274CB1F44E","66FCB20480E523BE","8A27A2B13FEA0921","EA2D79FABEDF731C","AB4F97DEC5B0FBE4","F8FA5E543F42F1A2","198FEE32ADA95FBD","21BEF59B8A905DAE","3E3B7424DCD3885A","39EAD867EEDB302F","02B596C48235ADF4","F4A4A12CDC53BA7A","2091B5D37E2F0099","53737E36B05D90C1","76C1E3FB436A3C13","0934B0780E07D8F5","8EC89121D91B8EC2","E26674AF2EF473D3","B3264C55268F919F","845DA4FC5F018DA8","063C0359647B8A9B","9EEAEFD7D06A1C12","96CA8DA1D52C8DFF","A56F1C0A384FD08A",
                "F52E183EE865347C","EF86639ED8782E4D","0BFA73798B0E9A5D","248DB00DF8AFD0EC","804D042905F7B207","CD005FD2CAB7EF23","06EBA95112C2A195","7750ECAC74FB1998","9E86CDFAA3F5F86F","8843FC2122CA0892","68550385EDF4E3F3","F554EDCCF5FD7D12","D842B4B405829B75","4D94E1B1C51BAACE","677A2BDB060671A7","81567B7A50068910","D4F97AB99D05A4C2","28B80F46FE76816C","D4626E8E9848EE6F","1A33E635730131C4","1418C53E851B845B","1C4C07ED7636611B","F9AA31079D3B3170","9182D6A0121AD246","30C5388E4DD75E25","8AE8C43B1A9B503B","D25DE2BD76846482","F3B5389D18201534","6C97FFECCD001B0F","4EB29021EBF43B5B",
                "1C345F8B71CE56C0","35AA4F069EDB87C4","09B6259DD92329C5","5189DAC8F3933118","2862A69F72C77FB0","F97258FA461FEB63","06296FD70EAECC1C","8F5ECE290FED0940","DF9A902BD50C506C","42560E9BB191CB7C","6266476A875EDAC4","9B91C5057CD27A70","86EE167957C5AB21","629395B4A2C109B9","C5A8693C7B4AA7E1","AACDB68A0F887CBE","ADAC0387AA0B2774","95B318B75B581AC9","85C16BA5629BEF32","F0C1A61260219197","C7A8E962FD50DA84","614055B1CE6C40C3","7A1C42412EFB776A","120DD1D26F77DB32","ABCF61C1033A6140","CF226832C70FEBC9","87E7622D63A66F5F","F8DB83FFD3A282DF","896705893CF6F0FB","9E68171C76E6CDCE",
                "9E37BEE44386D22E","0508349252E3566D","CA95EFDB9F338C88","41299CC517CA9632","DC1E705F55CA94E5","9FE4215787E6E5A1","AB4F353CDC65D827","F9F792B6A40B0387","A8D5DA97E611D7EA","DD9B8F16846ACDA5","5E34A23DD554F702","0FA23AD9CE7C1912","9721C3D313F70171","FB65655BE6997B29","7F9D66C23F889AEF","8699C6C2669EA693","013F4B94383C01C8","2412A6A51140637C","41F8C199BCA4538C","AE64C3B8ACADAB5D","AD22060B08BDC3D4","ABA30CA63CD20ED6","1BFF62F4A3E7F6FC","7F0FEBCAC1C247E2","3970BBCFED042F9F","1551DEA9D6E5E2C4","67EA8210B7710DCE","3BB61975673F3011","7D07046B26F947D4","428C4ABDF25EB349",
                "099A1D40F50A045F","C0D57202BFA90EAC","22A44B682169DE95","CD70EC02812180A0","3DC4DB74B2B10CBD","CBA58BE466367FDB","78634B1F886ECB88","C8F84E120F82E572","24364F72CCF49B75","63AA7ADA6602B3D9","3CEFA1C315B7CAC2","4E318C0FD7914383","201EA6AA2ADEC5B2","7E3051A949ED0DE7","EF1CDEFF13512B26","6613F3920976D0A9","95EB03CA366762F8","B7865EAF3B72788E","40757856AC3434C0","6BEC6928823ECED3" };
        //@NoUseNewKeyEx return 1;//如果没有使用这个功能，直接返回1


        for (n = 0; n < 255; n++)
        {
            DevicePath= j9.FindPort(n );
            if (j9.get_LastError() != 0) return (int)j9.get_LastError();
            outString = j9.EncString(EncInString[myrnd], DevicePath);
            if ((j9.get_LastError() == 0) && (outString.compareTo(EncOutString[myrnd]) == 0)) return 0;
        }
        return -92;
    }
}
